#include<bits/stdc++.h>
using namespace std;
struct library
{
	int len;
	string name;
	bool operator < (const library &x) const
	{
		return name<x.name;
	}
}book[10000];

struct reader
{
	int num;
	string str;
}reader[10000]; 

int main()
{
	int n,q;
	while(cin>>n>>q)
	{
		for(int i=1;i<=n;i++)
		{
			cin>>book[i].name;
			book[i].len=book[i].name.size();
		}
		sort(book+1,book+n+1);
		for(int i=1;i<=q;i++)
		{
			int flag=0;
			cin>>reader[i].num>>reader[i].str;
			for(int j=1;j<=n;j++)
			{
				if(reader[i].str==book[j].name.substr(book[j].len-reader[i].num,book[j].len))
				{
					flag=1;
					cout<<book[j].name<<endl;
					break;
				}
			}
			if(flag==0)
				cout<<"-1"<<endl;
		}
	}
    return 0;
}
